﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using DevMaker.SIC.Model;


namespace DevMaker.SIC.Dao {
    public class PuntoVentaDao {
        public List<PuntoVenta> ObtieneTodos() {
            const string storeName = "SP_PuntosVentas_L";
            var list = new List<PuntoVenta>();
            var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SIC_Connection"].ToString());
            try {
                conn.Open();
                var command = new SqlCommand(storeName, conn);
                command.CommandType = CommandType.StoredProcedure;
                var reader = command.ExecuteReader();
                while (reader.Read()) {
                    var p = new PuntoVenta();
                    p.ReadFromDataReader(reader);
                    list.Add(p);
                }
            } catch (Exception ex) {
                Console.Write(ex.InnerException);
            } finally {
                conn.Close();
            }
            return list;
        }

        public List<PuntoVenta> ObtieneActivosSinTurnos(){
            const string storeName = "SP_PuntosVentas_sin_turno_activo_L";
            var list = new List<PuntoVenta>();
            var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["SIC_Connection"].ToString());
            try {
                conn.Open();
                var command = new SqlCommand(storeName, conn);
                command.CommandType = CommandType.StoredProcedure;
                var reader = command.ExecuteReader();
                while (reader.Read()) {
                    var p = new PuntoVenta();
                    p.ReadFromDataReader(reader);
                    list.Add(p);
                }
            } catch (Exception ex) {
                Console.Write(ex.InnerException);
            } finally {
                conn.Close();
            }
            return list;
            
        }
    }
}
